import 'package:flutter/material.dart';
import 'package:flutter_enjoy/pages/Home/Homenav.dart';

class Home extends StatefulWidget {
  const Home({super.key});

  @override
  // ignore: library_private_types_in_public_api
  _HomeState createState() => _HomeState();
}

class _HomeState extends State<Home> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: const Color(0xFFF6F7FB),
      appBar: PreferredSize(
        preferredSize: const Size.fromHeight(56),
        child: AppBar(
          elevation: 0,
          backgroundColor: Colors.white,
          centerTitle: true,
          title: const Text(
            '享+本地生活',
            style: TextStyle(
              color: Color(0xFF222222),
              fontWeight: FontWeight.bold,
              fontSize: 18,
            ),
          ),
          leading: Padding(
            padding: const EdgeInsets.only(left: 16, top: 8),
          ),
          actions: [
            IconButton(
              icon: Icon(Icons.more_horiz, color: Color(0xFF222222)),
              onPressed: () {},
            ),
            SizedBox(width: 8),
            IconButton(
              icon: Icon(Icons.notifications_none, color: Color(0xFF222222)),
              onPressed: () {},
            ),
            SizedBox(width: 8),
          ],
          shape: const RoundedRectangleBorder(
            borderRadius: BorderRadius.vertical(
              bottom: Radius.circular(16),
            ),
          ),
        ),
      ),
      body: ListView(
        padding: const EdgeInsets.symmetric(horizontal: 16),
        children: [
          const SizedBox(height: 16),
          HomeNav(),
          const SizedBox(height: 16),
          ClipRRect(
            borderRadius: BorderRadius.circular(12),
            child: Image.asset(
              'assets/images/banner@2x.jpg',
              fit: BoxFit.cover,
              height: 140,
              width: double.infinity,
            ),
          ),
          const SizedBox(height: 20),
          // 公告区块
          Row(
            children: [
              Image.asset(
                'assets/images/notice@2x.png',
                width: 20,
                height: 20,
              ),
              const SizedBox(width: 6),
              const Text(
                '社区',
                style: TextStyle(
                  color: Color(0xFF222222),
                  fontWeight: FontWeight.bold,
                  fontSize: 16,
                ),
              ),
              Text(
                '公告',
                style: TextStyle(
                  color: Color(0xFFF6A623),
                  fontWeight: FontWeight.bold,
                  fontSize: 16,
                ),
              ),
            ],
          ),
          const SizedBox(height: 12),
          // 公告卡片
          _buildNoticeCard(),
          const SizedBox(height: 12),
          _buildNoticeCard(),
        ],
      ),
    );
  }

  Widget _buildNoticeCard() {
    return Container(
      padding: const EdgeInsets.all(16),
      margin: const EdgeInsets.only(bottom: 4),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(12),
        boxShadow: [
          BoxShadow(
            color: Colors.black.withOpacity(0.03),
            blurRadius: 8,
            offset: Offset(0, 2),
          ),
        ],
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: const [
          Text(
            '药品喷洒通知',
            style: TextStyle(
              fontWeight: FontWeight.bold,
              fontSize: 15,
              color: Color(0xFF222222),
            ),
          ),
          SizedBox(height: 6),
          Text(
            '社区定于8月3日中喷洒灭蚊药，提醒大家看管好小孩及宠物，不要到草坪中玩耍，以免造成不必要的危险。',
            style: TextStyle(
              fontSize: 13,
              color: Color(0xFF666666),
            ),
          ),
          SizedBox(height: 10),
          Text(
            '2022-08-03 16:00',
            style: TextStyle(
              fontSize: 12,
              color: Color(0xFFBBBBBB),
            ),
          ),
        ],
      ),
    );
  }
}
